package ejerciciosJFrame13;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@SuppressWarnings("serial")
public class Main extends JFrame implements ActionListener {
	private int anchoVentana = 200;
	private int altoVentana = 200;
	private JPanel p;
	private JTextField tPalabras;
	private JButton bAccion;
	private int estado;
	private String primeraPalabra;

	private void inicializar() {
		int anchoPantalla = Toolkit.getDefaultToolkit().getScreenSize().width;
		int altoPantalla = Toolkit.getDefaultToolkit().getScreenSize().height;
		setSize(anchoVentana, altoVentana);
		setLocation(anchoPantalla / 2 - anchoVentana / 2, altoPantalla / 2
				- altoVentana / 2);
		setTitle("Ejercicio 13");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}

	public Main() {
		inicializar();
		inicializarLayout();
		inicializarEstado();
		setVisible(true);
	}

	private void inicializarEstado() {
		estado=1;
		
	}

	private void inicializarLayout() {
		this.p = new JPanel(new GridLayout(2, 1));
		tPalabras = new JTextField();
		p.add(tPalabras);
		bAccion = new JButton("Segunda palabra");
		p.add(bAccion);
		bAccion.addActionListener(this);
		this.add(p);
	}

	public static void main(String[] args) {
		new Main();

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		switch (estado) {
		case 1:irAEstadoDos();estado=2;break;
		case 2:irAEstadoTres();estado=3;break;
		}
	}

	private void irAEstadoTres() {
		bAccion.setText("FIN");
		bAccion.setEnabled(false);
		tPalabras.setText(primeraPalabra+tPalabras.getText());
	}

	private void irAEstadoDos() {
		bAccion.setText("Concatenar");
		primeraPalabra=tPalabras.getText();
		tPalabras.setText("");
		
	}

}
